package com.kobe.algorithm.leetcode.case503;

import com.kobe.algorithm.leetcode.case107.Soution107S;

import java.util.Arrays;
import java.util.Stack;

/**
 * @author ：caopengfei
 * @date ：2021/3/6
 */
public class Solution {

    public int[] nextGreaterElements(int[] nums) {

//        Stack<Integer> stack = new Stack<>();
        int [] result = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
          int currentIdex = i;
          int num = nums[currentIdex];
          int mostNum = -1;
          int mostIndex = i+1;
          while(mostIndex< nums.length + i){
              int mostIndexTemp = mostIndex;
              if(mostIndexTemp >= nums.length){
                  mostIndexTemp = mostIndex -  nums.length;
              }
              if(num < nums[mostIndexTemp]){
                  mostNum = nums[mostIndexTemp];
                  break;
              }else{
                  mostIndex++;
              }
          }
          result[i] = mostNum;
        }
      return result;
    }

    public static void main(String[] args) {
        int [] nums = {1,2,5,3,9,6,7,8};
        Solution solution = new Solution();
        System.out.println(Arrays.toString(solution.nextGreaterElements(nums)));
    }



}
